package com.ruoyi.web.controller.eamp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eamp.domain.vo.UserAndEquipmentAndMy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eamp.domain.EampEquipmentUse;
import com.ruoyi.eamp.service.IEampEquipmentUseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仪器使用记录Controller
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/equipment_use")
public class EampEquipmentUseController extends BaseController
{
    @Autowired
    private IEampEquipmentUseService eampEquipmentUseService;

    /**
     * 查询仪器使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment_use:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampEquipmentUse eampEquipmentUse)
    {
        startPage();
        List<UserAndEquipmentAndMy> list = eampEquipmentUseService.selectEampEquipmentUseList(eampEquipmentUse);
        return getDataTable(list);
    }

    /**
     * 导出仪器使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment_use:export')")
    @Log(title = "仪器使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampEquipmentUse eampEquipmentUse)
    {
        List<UserAndEquipmentAndMy> list = eampEquipmentUseService.selectEampEquipmentUseList(eampEquipmentUse);
        ExcelUtil<UserAndEquipmentAndMy> util = new ExcelUtil<UserAndEquipmentAndMy>(UserAndEquipmentAndMy.class);
        util.exportExcel(response, list, "仪器使用记录数据");
    }

    /**
     * 获取仪器使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment_use:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(eampEquipmentUseService.selectEampEquipmentUseByLogId(logId));
    }

    /**
     * 新增仪器使用记录
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment_use:add')")
    @Log(title = "仪器使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EampEquipmentUse eampEquipmentUse)
    {
        return toAjax(eampEquipmentUseService.insertEampEquipmentUse(eampEquipmentUse));
    }

    /**
     * 修改仪器使用记录
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment_use:edit')")
    @Log(title = "仪器使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EampEquipmentUse eampEquipmentUse)
    {
        return toAjax(eampEquipmentUseService.updateEampEquipmentUse(eampEquipmentUse));
    }

    /**
     * 删除仪器使用记录
     */
    @PreAuthorize("@ss.hasPermi('eamp:equipment_use:remove')")
    @Log(title = "仪器使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(eampEquipmentUseService.deleteEampEquipmentUseByLogIds(logIds));
    }
}
